﻿
// MainFrm.cpp: CMainFrame 类的实现
//

#include "pch.h"
#include "framework.h"
#include "RTOC-Data-Interface.h"

#include "MainFrm.h"
#include "CSystemSetDlg.h"
#include "CParsSetDlg.h"
#include "CWellsCfgDlg.h"
#include "CWellTimeSpanSetDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//数据库存处理线程
//因一体化库较大，返回较慢，所以需要多个链接
_ConnectionPtr	OpenYqhDb()
{
	_ConnectionPtr	pCnn;
	try
	{
		CString strSvr = ReadINI(_T("SYSTEM"), _T("YQHDbName"));
		CString strUsr = ReadINI(_T("SYSTEM"), _T("YQHDbUsr"));
		CString strPwd = ReadINI(_T("SYSTEM"), _T("YQHDbPwd"));
		pCnn.CreateInstance("ADODB.Connection");
		CString  strConnect;
		strConnect.Format(_T("Provider=OraOLEDB.Oracle;Persist Security Info=True;Data Source=%s;User ID=%s;Password=%s;"), strSvr, strUsr, strPwd);
		pCnn->ConnectionTimeout = 45;
		pCnn->Open(_bstr_t(strConnect), "", "", adOpenUnspecified);
	}
	catch (_com_error e)//捕捉异常
	{
		pCnn = NULL;
	}
	return pCnn;
}
int	nYQHErrorTick1 = 0;
int	nYQHErrorTick2 = 0;
int	nYQHErrorTick3 = 0;
int	nYQHErrorTick4 = 0;
int nYQHUrlErrorTick1 = 0;
int nYQHUrlErrorTick2 = 0;

bool Thread_ExcuteYqhSQL(_ConnectionPtr	pCnn,CString strSQL)
{
	if (pCnn == NULL) return FALSE;
	try
	{
		_variant_t RecordsAffected;
		pCnn->Execute((_bstr_t)strSQL, &RecordsAffected, 1);
		gl.m_nYqhDataTime = CTime::GetCurrentTime().GetTime();
	}
	catch (...)
	{
		//WriteLog(_T("一体化数据库入库错误 ") + strSQL);
		//AfxMessageBox(strSQL);
		return FALSE;
	}
	return TRUE;
}
UINT YqhUrlThread1(LPVOID p)
{
	CString strTemp;

	// 将 URL 转换为 wchar_t*
	char* tt = wchar2char(gl.tlm.strURL4);
	std::string url(tt);
	delete[] tt;

	strTemp = _T("YqhUrlThread1: start .....");
	WriteLog(strTemp);

	while (1)
	{
		if (g_bExitApp)
		{
			strTemp = _T("YqhUrlThread1: 应用程序退出");
			WriteLog(strTemp);
			break;
		}
		::EnterCriticalSection(&m_cYqhUrl);
		int nCount = asyqhUrl.size();
		if (nCount > 100)
		{
			gl.m_strErrorMsg.Format(_T("一体化url队列记录数=%d"), nCount);
			strTemp = _T("YqhUrlThread1: 一体化url队列记录数超过100");
			WriteLog(strTemp);
		}
		if (nCount > 0)
		{
			std::string str = asyqhUrl.front();
			asyqhUrl.pop();
			::LeaveCriticalSection(&m_cYqhUrl);


			std::string result = PostJsonApi(url, str);
			if (result != "200")
			{
				nYQHUrlErrorTick1++;
				std::string ss = "post error; asyqhUrl.size:";
				ss += std::to_string(nCount);
				ss += " YqhOpratorUrl1  post json:" + str;
				WriteLog(ss);
			}
			else
			{
				nYQHUrlErrorTick1 = 0;
				std::string ss = "post ok; asyqhUrl.size:";
				ss += std::to_string(nCount);
				ss += " YqhOpratorUrl1  post json:" + str;
				WriteLog(ss);
			}

			if (nYQHUrlErrorTick1 > 10)
			{
				nYQHUrlErrorTick1 = 0;
				strTemp = _T("YqhUrlThread1: 一体化url上传错误..");
				WriteLog(strTemp);
			}
		}
		else
		{
			::LeaveCriticalSection(&m_cYqhUrl);
		}
	}
	return 1;
}


UINT YqhDbThread1(LPVOID p)
{
	CString strTemp;
	Sleep(1000);
	_ConnectionPtr	pCnn = OpenYqhDb();
	while (1)
	{
		if (g_bExitApp) break;
		::EnterCriticalSection(&m_cYqhSQL);
		int nCount = asYqhSQL.GetCount();
		if(nCount>100)
			gl.m_strErrorMsg.Format(_T("一体化入库队列记录数=%d"), nCount);
		if (nCount > 0)
		{
			CString strSQL = asYqhSQL.GetAt(0);
			asYqhSQL.RemoveAt(0);
			::LeaveCriticalSection(&m_cYqhSQL);
			if (!Thread_ExcuteYqhSQL(pCnn,strSQL))
				nYQHErrorTick1++;
			else
				nYQHErrorTick1 = 0;

			//一体化数据库重连
			if (nYQHErrorTick1 > 10)
			{
				nYQHErrorTick1 = 0;
				WriteLog(_T("一体化数据库重连..."));
				pCnn = OpenYqhDb();
			}
			Sleep(1);
		}
		else
		{
			::LeaveCriticalSection(&m_cYqhSQL);
			Sleep(10);
		}
	}
	return 1;
}

UINT YqhDbThread2(LPVOID p)
{
	CString strTemp;
	Sleep(1000);
	_ConnectionPtr	pCnn = OpenYqhDb();
	while (1)
	{
		if (g_bExitApp) break;
		::EnterCriticalSection(&m_cYqhSQL);
		int nCount = asYqhSQL.GetCount();
		if (nCount > 0)
		{
			CString strSQL = asYqhSQL.GetAt(0);
			asYqhSQL.RemoveAt(0);
			::LeaveCriticalSection(&m_cYqhSQL);
			if (!Thread_ExcuteYqhSQL(pCnn, strSQL))
				nYQHErrorTick2++;
			else
				nYQHErrorTick2 = 0;

			//一体化数据库重连
			if (nYQHErrorTick2 > 10)
			{
				nYQHErrorTick2 = 0;
				WriteLog(_T("一体化数据库重连..."));
				pCnn = OpenYqhDb();
			}
			Sleep(1);
		}
		else
		{
			::LeaveCriticalSection(&m_cYqhSQL);
			Sleep(10);
		}
	}
	return 1;
}

UINT YqhDbThread3(LPVOID p)
{
	CString strTemp;
	Sleep(1000);
	_ConnectionPtr	pCnn = OpenYqhDb();
	while (1)
	{
		if (g_bExitApp) break;
		::EnterCriticalSection(&m_cYqhSQL);
		int nCount = asYqhSQL.GetCount();
		if (nCount > 0)
		{
			CString strSQL = asYqhSQL.GetAt(0);
			asYqhSQL.RemoveAt(0);
			::LeaveCriticalSection(&m_cYqhSQL);
			if (!Thread_ExcuteYqhSQL(pCnn, strSQL))
				nYQHErrorTick3++;
			else
				nYQHErrorTick3 = 0;

			//一体化数据库重连
			if (nYQHErrorTick3 > 10)
			{
				nYQHErrorTick3 = 0;
				WriteLog(_T("一体化数据库重连..."));
				pCnn = OpenYqhDb();
			}
			Sleep(1);
		}
		else
		{
			::LeaveCriticalSection(&m_cYqhSQL);
			Sleep(10);
		}
	}
	return 1;
}

UINT YqhDbThread4(LPVOID p)
{
	CString strTemp;
	Sleep(1000);
	_ConnectionPtr	pCnn = OpenYqhDb();
	while (1)
	{
		if (g_bExitApp) break;
		::EnterCriticalSection(&m_cYqhSQL);
		int nCount = asYqhSQL.GetCount();
		if (nCount > 0)
		{
			CString strSQL = asYqhSQL.GetAt(0);
			asYqhSQL.RemoveAt(0);
			::LeaveCriticalSection(&m_cYqhSQL);
			if (!Thread_ExcuteYqhSQL(pCnn, strSQL))
				nYQHErrorTick4++;
			else
				nYQHErrorTick4 = 0;

			//一体化数据库重连
			if (nYQHErrorTick4 > 10)
			{
				nYQHErrorTick4 = 0;
				WriteLog(_T("一体化数据库重连..."));
				pCnn = OpenYqhDb();
			}
			Sleep(1);
		}
		else
		{
			::LeaveCriticalSection(&m_cYqhSQL);
			Sleep(10);
		}
	}
	return 1;
}

///////////////////////////////////////////////////////////////////////////////////////////
//中心库
bool Thread_ExcuteZxkSQL(_ConnectionPtr	pCnn, CString strSQL)
{
	if (pCnn == NULL) return FALSE;
	try
	{
		_variant_t RecordsAffected;
		pCnn->Execute((_bstr_t)strSQL, &RecordsAffected, 1);
	}
	catch (...)
	{
		//WriteLog(_T("中心库入库错误 ") + strSQL);
		//AfxMessageBox(strSQL);
		return FALSE;
	}
	return TRUE;
}
_ConnectionPtr	OpenMasterDb()
{
	_ConnectionPtr	pCnn;
	try
	{
		CString strSvr = ReadINI(_T("SYSTEM"), _T("MasterDbName"));
		CString strUsr = ReadINI(_T("SYSTEM"), _T("MasterDbUsr"));
		CString strPwd = ReadINI(_T("SYSTEM"), _T("MasterDbPwd"));
		pCnn.CreateInstance("ADODB.Connection");
		CString  strConnect;
		strConnect.Format(_T("Provider=OraOLEDB.Oracle;Persist Security Info=True;Data Source=%s;User ID=%s;Password=%s;"), strSvr, strUsr, strPwd);
		pCnn->ConnectionTimeout = 45;
		pCnn->Open(_bstr_t(strConnect), "", "", adOpenUnspecified);
	}
	catch (_com_error e)//捕捉异常
	{
		pCnn = NULL;
	}
	return pCnn;
}

int	nZXQErrorTick1 = 0;
int	nZXQErrorTick2 = 0;
int	nZXQErrorTick3 = 0;
int	nZXQErrorTick4 = 0;

UINT ZxkDbThread1(LPVOID p)
{
	CString strTemp;
	Sleep(1000);
	_ConnectionPtr	pCnn = OpenMasterDb();
	while (1)
	{
		if (g_bExitApp) break;
		::EnterCriticalSection(&m_cZxkSQL);
		int nCount = asZxkSQL.GetCount();
		if (nCount > 100)
			gl.m_strErrorMsg.Format(_T("中心库入库队列记录数=%d"), nCount);
		if (nCount > 0)
		{
			CString strSQL = asZxkSQL.GetAt(0);
			asZxkSQL.RemoveAt(0);
			::LeaveCriticalSection(&m_cZxkSQL);
			if (!Thread_ExcuteZxkSQL(pCnn, strSQL))
				nZXQErrorTick1++;
			else
				nZXQErrorTick1 = 0;
			//中心库重连
			if (nZXQErrorTick1 > 10)
			{
				nZXQErrorTick1 = 0;
				WriteLog(_T("中心库重连..."));
				pCnn = OpenMasterDb();
			}
			Sleep(1);
		}
		else
		{
			::LeaveCriticalSection(&m_cZxkSQL);
			Sleep(10);
		}
	}
	return 1;
}

UINT ZxkDbThread2(LPVOID p)
{
	CString strTemp;
	Sleep(1000);
	_ConnectionPtr	pCnn = OpenMasterDb();
	while (1)
	{
		if (g_bExitApp) break;
		::EnterCriticalSection(&m_cZxkSQL);
		int nCount = asZxkSQL.GetCount();
		if (nCount > 0)
		{
			CString strSQL = asZxkSQL.GetAt(0);
			asZxkSQL.RemoveAt(0);
			::LeaveCriticalSection(&m_cZxkSQL);
			if (!Thread_ExcuteZxkSQL(pCnn, strSQL))
				nZXQErrorTick2++;
			else
				nZXQErrorTick2 = 0;
			//中心库重连
			if (nZXQErrorTick2 > 10)
			{
				nZXQErrorTick2 = 0;
				WriteLog(_T("中心库重连..."));
				pCnn = OpenMasterDb();
			}
			Sleep(1);
		}
		else
		{
			::LeaveCriticalSection(&m_cZxkSQL);
			Sleep(10);
		}
	}
	return 1;
}

UINT ZxkDbThread3(LPVOID p)
{
	CString strTemp;
	Sleep(1000);
	_ConnectionPtr	pCnn = OpenMasterDb();
	while (1)
	{
		if (g_bExitApp) break;
		::EnterCriticalSection(&m_cZxkSQL);
		int nCount = asZxkSQL.GetCount();
		if (nCount > 0)
		{
			CString strSQL = asZxkSQL.GetAt(0);
			asZxkSQL.RemoveAt(0);
			::LeaveCriticalSection(&m_cZxkSQL);
			if (!Thread_ExcuteZxkSQL(pCnn, strSQL))
				nZXQErrorTick3++;
			else
				nZXQErrorTick3 = 0;
			//中心库重连
			if (nZXQErrorTick3 > 10)
			{
				nZXQErrorTick3 = 0;
				WriteLog(_T("中心库重连..."));
				pCnn = OpenMasterDb();
			}
			Sleep(1);
		}
		else
		{
			::LeaveCriticalSection(&m_cZxkSQL);
			Sleep(10);
		}
	}
	return 1;
}

UINT ZxkDbThread4(LPVOID p)
{
	CString strTemp;
	Sleep(1000);
	_ConnectionPtr	pCnn = OpenMasterDb();
	while (1)
	{
		if (g_bExitApp) break;
		::EnterCriticalSection(&m_cZxkSQL);
		int nCount = asZxkSQL.GetCount();
		if (nCount > 0)
		{
			CString strSQL = asZxkSQL.GetAt(0);
			asZxkSQL.RemoveAt(0);
			::LeaveCriticalSection(&m_cZxkSQL);
			if (!Thread_ExcuteZxkSQL(pCnn, strSQL))
				nZXQErrorTick4++;
			else
				nZXQErrorTick4 = 0;
			//中心库重连
			if (nZXQErrorTick4 > 10)
			{
				nZXQErrorTick4 = 0;
				WriteLog(_T("中心库重连..."));
				pCnn = OpenMasterDb();
			}
			Sleep(1);
		}
		else
		{
			::LeaveCriticalSection(&m_cZxkSQL);
			Sleep(10);
		}
	}
	return 1;
}

///////////////////////////////////////////////////////////////////////////////////////////
//KD库
bool Thread_ExcuteKdSQL(_ConnectionPtr	pCnn, CString strSQL)
{
	if (pCnn == NULL) return FALSE;
	try
	{
		_variant_t RecordsAffected;
		pCnn->Execute((_bstr_t)strSQL, &RecordsAffected, 1);
		gl.m_nKdDataTime = CTime::GetCurrentTime().GetTime();
	}
	catch (...)
	{
		//WriteLog(_T("KD入库错误 ") + strSQL);
		//AfxMessageBox(strSQL);
		return FALSE;
	}
	return TRUE;
}

_ConnectionPtr	OpenKdDb()
{
	_ConnectionPtr	pCnn;
	try
	{
		CString strSvr = ReadINI(_T("SYSTEM"), _T("KdDbName"));
		CString strUsr = ReadINI(_T("SYSTEM"), _T("KdDbUsr"));
		CString strPwd = ReadINI(_T("SYSTEM"), _T("KdDbPwd"));
		pCnn.CreateInstance("ADODB.Connection");
		CString  strConnect;
		strConnect.Format(_T("Provider=OraOLEDB.Oracle;Persist Security Info=True;Data Source=%s;User ID=%s;Password=%s;"), strSvr, strUsr, strPwd);
		pCnn->ConnectionTimeout = 45;
		pCnn->Open(_bstr_t(strConnect), "", "", adOpenUnspecified);
	}
	catch (_com_error e)//捕捉异常
	{
		pCnn = NULL;
	}
	return pCnn;
}

int	nKDErrorTick1 = 0;
int	nKDErrorTick2 = 0;

UINT KdDbThread1(LPVOID p)
{
	CString strTemp;
	Sleep(1000);
	_ConnectionPtr	pCnn = OpenMasterDb();
	while (1)
	{
		if (g_bExitApp) break;
		::EnterCriticalSection(&m_cKdSQL);
		int nCount = asKdSQL.GetCount();
		if (nCount > 100)
			gl.m_strErrorMsg.Format(_T("KD库入库队列记录数=%d"), nCount);
		if (nCount > 0)
		{
			CString strSQL = asKdSQL.GetAt(0);
			asKdSQL.RemoveAt(0);
			::LeaveCriticalSection(&m_cKdSQL);
			if (!Thread_ExcuteKdSQL(pCnn,strSQL))
				nKDErrorTick1++;
			else
				nKDErrorTick1 = 0;
			//KD库重连
			if (nKDErrorTick1 > 10)
			{
				nKDErrorTick1 = 0;
				WriteLog(_T("KD库重连..."));
				pCnn = OpenKdDb();
			}
			Sleep(1);
		}
		else
		{
			::LeaveCriticalSection(&m_cKdSQL);
			Sleep(10);
		}
	}
	return 1;
}

UINT KdDbThread2(LPVOID p)
{
	CString strTemp;
	Sleep(1000);
	_ConnectionPtr	pCnn = OpenMasterDb();
	while (1)
	{
		if (g_bExitApp) break;
		::EnterCriticalSection(&m_cKdSQL);
		int nCount = asKdSQL.GetCount();
		if (nCount > 100)
			gl.m_strErrorMsg.Format(_T("KD库入库队列记录数=%d"), nCount);
		if (nCount > 0)
		{
			CString strSQL = asKdSQL.GetAt(0);
			asKdSQL.RemoveAt(0);
			::LeaveCriticalSection(&m_cKdSQL);
			if (!Thread_ExcuteKdSQL(pCnn, strSQL))
				nKDErrorTick2++;
			else
				nKDErrorTick2 = 0;
			//KD库重连
			if (nKDErrorTick2 > 10)
			{
				nKDErrorTick2 = 0;
				WriteLog(_T("KD库重连..."));
				pCnn = OpenKdDb();
			}
			Sleep(1);
		}
		else
		{
			::LeaveCriticalSection(&m_cKdSQL);
			Sleep(10);
		}
	}
	return 1;
}

UINT RedisThread(LPVOID p)
{
	CString strTemp;
	Sleep(1000);
	while (1)
	{
		if (g_bExitApp) break;
		int nCount = m_aRR.GetCount();
		if (nCount > 0)
		{
			REDIS_REC rr= m_aRR.GetAt(0);
			::EnterCriticalSection(&m_cRedis);
			m_aRR.RemoveAt(0);
			int nReturn = Bxhy_Redis_SetKey(rr.strFieldName, rr.strValue);
			if (nReturn == 1)
				gl.m_nRedisDataTime =  CTime::GetCurrentTime().GetTime();
			else
				Redis_Connect();
			::LeaveCriticalSection(&m_cRedis);
			Sleep(1);
		}
		else
			Sleep(10);
	}
	return 1;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWndEx)

const int  iMaxUserToolbars = 10;
const UINT uiFirstUserToolBarId = AFX_IDW_CONTROLBAR_FIRST + 40;
const UINT uiLastUserToolBarId = uiFirstUserToolBarId + iMaxUserToolbars - 1;

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx)
	ON_WM_CREATE()
	ON_COMMAND(ID_VIEW_CUSTOMIZE, &CMainFrame::OnViewCustomize)
	ON_REGISTERED_MESSAGE(AFX_WM_CREATETOOLBAR, &CMainFrame::OnToolbarCreateNew)
	ON_COMMAND_RANGE(ID_VIEW_APPLOOK_WIN_2000, ID_VIEW_APPLOOK_WINDOWS_7, &CMainFrame::OnApplicationLook)
	ON_UPDATE_COMMAND_UI_RANGE(ID_VIEW_APPLOOK_WIN_2000, ID_VIEW_APPLOOK_WINDOWS_7, &CMainFrame::OnUpdateApplicationLook)
	ON_COMMAND(ID_SYS_CFG, &CMainFrame::OnSysCfg)
	ON_COMMAND(ID_SYS_PARSCFG, &CMainFrame::OnSysParscfg)
	ON_COMMAND(ID_SYS_WELLS, &CMainFrame::OnSysWells)
	ON_COMMAND(ID_SYS_START, &CMainFrame::OnSysStart)
	ON_COMMAND(ID_SYS_STOP, &CMainFrame::OnSysStop)
	ON_UPDATE_COMMAND_UI(ID_SYS_START, &CMainFrame::OnUpdateSysStart)
	ON_UPDATE_COMMAND_UI(ID_SYS_STOP, &CMainFrame::OnUpdateSysStop)
	ON_COMMAND(ID_APP_EXIT, &CMainFrame::OnAppExit)
	ON_WM_TIMER()
	ON_WM_CLOSE()
	ON_COMMAND(ID_INDICATOR_TXT1, NULL)
	ON_COMMAND(ID_SYS_WELLTIMESPAN, &CMainFrame::OnSysWelltimespan)
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // 状态行指示器
	ID_INDICATOR_TXT1,
	ID_INDICATOR_TXT2
};

// CMainFrame 构造/析构

CMainFrame::CMainFrame() noexcept
{
	// TODO: 在此添加成员初始化代码
	theApp.m_nAppLook = theApp.GetInt(_T("ApplicationLook"), ID_VIEW_APPLOOK_OFF_2007_BLACK);
	m_bFirst = TRUE;
	for (int i = 0; i < MAXWELLS; i++)
	{
		pThread[i] = NULL;
	}
	m_nWells = 0;
}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWndEx::OnCreate(lpCreateStruct) == -1)
		return -1;

	BOOL bNameValid;

	if (!m_wndMenuBar.Create(this))
	{
		TRACE0("未能创建菜单栏\n");
		return -1;      // 未能创建
	}

	m_wndMenuBar.SetPaneStyle(m_wndMenuBar.GetPaneStyle() | CBRS_SIZE_DYNAMIC | CBRS_TOOLTIPS | CBRS_FLYBY);

	// 防止菜单栏在激活时获得焦点
	CMFCPopupMenu::SetForceMenuFocus(FALSE);

	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!m_wndToolBar.LoadToolBar(theApp.m_bHiColorIcons ? IDR_MAINFRAME_256 : IDR_MAINFRAME))
	{
		TRACE0("未能创建工具栏\n");
		return -1;      // 未能创建
	}

	CString strToolBarName;
	bNameValid = strToolBarName.LoadString(IDS_TOOLBAR_STANDARD);
	ASSERT(bNameValid);
	m_wndToolBar.SetWindowText(strToolBarName);

	CString strCustomize;
	bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE);
	ASSERT(bNameValid);
	m_wndToolBar.EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize);

	// 允许用户定义的工具栏操作: 
	InitUserToolbars(nullptr, uiFirstUserToolBarId, uiLastUserToolBarId);

	if (!m_wndStatusBar.Create(this))
	{
		TRACE0("未能创建状态栏\n");
		return -1;      // 未能创建
	}
	m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT));

	// TODO: 如果您不希望工具栏和菜单栏可停靠，请删除这五行
	m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockPane(&m_wndMenuBar);
	DockPane(&m_wndToolBar);


	// 启用 Visual Studio 2005 样式停靠窗口行为
	CDockingManager::SetDockingMode(DT_SMART);
	// 启用 Visual Studio 2005 样式停靠窗口自动隐藏行为
	EnableAutoHidePanes(CBRS_ALIGN_ANY);
	// 基于持久值设置视觉管理器和样式
	OnApplicationLook(theApp.m_nAppLook);

	// 启用工具栏和停靠窗口菜单替换
	EnablePaneMenu(TRUE, ID_VIEW_CUSTOMIZE, strCustomize, ID_VIEW_TOOLBAR);

	// 启用快速(按住 Alt 拖动)工具栏自定义
	CMFCToolBar::EnableQuickCustomization();

	if (CMFCToolBar::GetUserImages() == nullptr)
	{
		// 加载用户定义的工具栏图像
		if (m_UserImages.Load(_T(".\\UserImages.bmp")))
		{
			CMFCToolBar::SetUserImages(&m_UserImages);
		}
	}
	m_wndStatusBar.SetPaneWidth(0, 150);
	m_wndStatusBar.SetPaneWidth(1, 200);

	m_nTimer = SetTimer(9001, 1000, NULL);
	return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CFrameWndEx::PreCreateWindow(cs) )
		return FALSE;
	// TODO: 在此处通过修改
	//  CREATESTRUCT cs 来修改窗口类或样式

	return TRUE;
}

// CMainFrame 诊断

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CFrameWndEx::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CFrameWndEx::Dump(dc);
}
#endif //_DEBUG


// CMainFrame 消息处理程序

void CMainFrame::OnViewCustomize()
{
	CMFCToolBarsCustomizeDialog* pDlgCust = new CMFCToolBarsCustomizeDialog(this, TRUE /* 扫描菜单*/);
	pDlgCust->EnableUserDefinedToolbars();
	pDlgCust->Create();
}

LRESULT CMainFrame::OnToolbarCreateNew(WPARAM wp,LPARAM lp)
{
	LRESULT lres = CFrameWndEx::OnToolbarCreateNew(wp,lp);
	if (lres == 0)
	{
		return 0;
	}

	CMFCToolBar* pUserToolbar = (CMFCToolBar*)lres;
	ASSERT_VALID(pUserToolbar);

	BOOL bNameValid;
	CString strCustomize;
	bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE);
	ASSERT(bNameValid);

	pUserToolbar->EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize);
	return lres;
}

void CMainFrame::OnApplicationLook(UINT id)
{
	CWaitCursor wait;

	theApp.m_nAppLook = id;

	switch (theApp.m_nAppLook)
	{
	case ID_VIEW_APPLOOK_WIN_2000:
		CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManager));
		break;

	case ID_VIEW_APPLOOK_OFF_XP:
		CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOfficeXP));
		break;

	case ID_VIEW_APPLOOK_WIN_XP:
		CMFCVisualManagerWindows::m_b3DTabsXPTheme = TRUE;
		CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
		break;

	case ID_VIEW_APPLOOK_OFF_2003:
		CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2003));
		CDockingManager::SetDockingMode(DT_SMART);
		break;

	case ID_VIEW_APPLOOK_VS_2005:
		CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerVS2005));
		CDockingManager::SetDockingMode(DT_SMART);
		break;

	case ID_VIEW_APPLOOK_VS_2008:
		CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerVS2008));
		CDockingManager::SetDockingMode(DT_SMART);
		break;

	case ID_VIEW_APPLOOK_WINDOWS_7:
		CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows7));
		CDockingManager::SetDockingMode(DT_SMART);
		break;

	default:
		switch (theApp.m_nAppLook)
		{
		case ID_VIEW_APPLOOK_OFF_2007_BLUE:
			CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_LunaBlue);
			break;

		case ID_VIEW_APPLOOK_OFF_2007_BLACK:
			CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_ObsidianBlack);
			break;

		case ID_VIEW_APPLOOK_OFF_2007_SILVER:
			CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Silver);
			break;

		case ID_VIEW_APPLOOK_OFF_2007_AQUA:
			CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Aqua);
			break;
		}

		CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007));
		CDockingManager::SetDockingMode(DT_SMART);
	}

	RedrawWindow(nullptr, nullptr, RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_UPDATENOW | RDW_FRAME | RDW_ERASE);

	theApp.WriteInt(_T("ApplicationLook"), theApp.m_nAppLook);
}

void CMainFrame::OnUpdateApplicationLook(CCmdUI* pCmdUI)
{
	pCmdUI->SetRadio(theApp.m_nAppLook == pCmdUI->m_nID);
}


BOOL CMainFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle, CWnd* pParentWnd, CCreateContext* pContext)
{
	// 基类将执行真正的工作

	if (!CFrameWndEx::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext))
	{
		return FALSE;
	}


	// 为所有用户工具栏启用自定义按钮
	BOOL bNameValid;
	CString strCustomize;
	bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE);
	ASSERT(bNameValid);

	for (int i = 0; i < iMaxUserToolbars; i ++)
	{
		CMFCToolBar* pUserToolbar = GetUserToolBarByIndex(i);
		if (pUserToolbar != nullptr)
		{
			pUserToolbar->EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize);
		}
	}

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//功能性测试代码
int get_soap()
{
	CString strTemp;
	CString URLGET = _T("http://192.168.147.1:9600/app_pages/AppWebService.asmx/AppInterface?strComm=SysLogin&strPars=string"); //web api地址
	char* ss = wchar2char(URLGET);
	struct soap *soap = soap_new();
	char * body;
	soap->http_extra_header = "Authorization: Bearer 1234567890";    //添加http头部信息
	soap_register_plugin(soap, http_get);
	if (soap_http_get_connect(soap, (LPSTR)(ss), NULL) || soap_begin_recv(soap))
	{
		soap_print_fault(soap, stderr);
		return -1;
	}
	if (soap->http_content)
	{
		char* pc = new char[200];
		strcpy(pc, soap->http_content);
		strTemp.Format(_T("HTTP CONTENT TYPE:%s\n"), char2wchar(pc));
		delete[] pc;
	}
	size_t len;
	soap_http_body(soap, &body, &len);
	soap_end_recv(soap);
	if (body)
	{
		strTemp.Format(_T("Get receive body is:%s\n"), char2wchar(body));
		AfxMessageBox(strTemp);
	}
	soap_end(soap);
	soap_done(soap);
	delete[]ss;
	return 0;
}

/*
int postSoap()
{
	CString strTemp;
	const char URLPost[] = "http://192.168.147.1:9600/app_pages/appwebservice.asmx/AppInterface";
	const char context[] = "strComm=SysLogin&strPars=sdfadsfasd";
	struct soap *soap = soap_new();
	char *buf=NULL;
	size_t len;
	// chunking conserves memory and is generally faster: 
	soap_set_omode(soap, SOAP_IO_CHUNK);
	// enable the following line to compress messages 
	//soap_set_omode(soap, SOAP_ENC_ZLIB);
	soap_register_plugin(soap, http_post);
	//if (soap_post_connect(soap, URLPost, NULL, "application/json") || soap_send(soap, context) || soap_end_send(soap))
	if (soap_post_connect(soap, URLPost, NULL, "application/x-www-form-urlencoded") || soap_send(soap, context) || soap_end_send(soap))
		{
		soap_print_fault(soap, stderr);
		printf("1111\n");
	}
	if (soap_begin_recv(soap) || soap_http_body(soap, &buf, &len) || soap_end_recv(soap))
	{
		soap_print_fault(soap, stderr);
		printf("222\n");
	}
	strTemp.Format(_T("POST RECEIVE buf is %s\n"), char2wchar(buf));
	AfxMessageBox(strTemp);
	soap_closesock(soap);
	char* pc = new char[len];
	strcpy(pc, soap->http_content);
	strTemp.Format(_T("Receives %lu bytes of type %s:\n"), (unsigned long)len, char2wchar(pc));
	delete[] pc;
	return 0;
}*/
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void CMainFrame::OnSysCfg()
{
	// TODO: 在此添加命令处理程序代码
	CSystemSetDlg dlg;
	dlg.DoModal();
}

void CMainFrame::OnSysParscfg()
{
	// TODO: 在此添加命令处理程序代码
	if (!g_bExitApp)
	{
		OnSysStop();
	}
	WriteLog(_T("进入井参数配置界面..."));
	CParsSetDlg dlg;
	dlg.DoModal();
}

void CMainFrame::OnSysWells()
{
	// TODO: 在此添加命令处理程序代码
	WriteLog(_T("进入井管理界面..."));
	if (!g_bExitApp)
	{
		OnSysStop();
	}
	CWellsCfgDlg dlg;
	dlg.DoModal();
	gl.m_bResetList = TRUE;
}

void CMainFrame::OnSysWelltimespan()
{
	// TODO: 在此添加命令处理程序代码
	if (!g_bExitApp)
	{
		OnSysStop();
	}
	WriteLog(_T("进入井井时间偏差调整界面..."));
	CWellTimeSpanSetDlg dlg;
	dlg.DoModal();
}

void CMainFrame::Test()
{
	//CString strTemp, strFileName;
	//CStdioFile stdFile;
	//CFileException e;
	//strFileName.Format(_T("%s\\JsonPars.txt"), m_strAppPath);
	//BOOL result = stdFile.Open(strFileName, CFile::modeRead, &e);
	//if (!result)
	//{
	//	return;
	//}
	//CString strBuf = _T("");
	//while (1)
	//{
	//	if (!stdFile.ReadString(strTemp))
	//		break;

	//	strBuf = strBuf + strTemp;
	//}
	//stdFile.Close();
	//gl.DepthIndex = gl.pi.FindCurDepthIndex();

	//SINGLE_WELL sw= gl.tlm.m_aWells.GetAt(0);
	//sw.ParseParsNameJson(strBuf);
	//CString strPost=sw.GenPostContent();
	//strFileName.Format(_T("%s\\JsonVal.txt"), m_strAppPath);
	//result = stdFile.Open(strFileName, CFile::modeRead, &e);
	//if (!result)
	//{
	//	return;
	//}
	//stdFile.ReadString(strTemp);		//第一行不需要
	//stdFile.Close();
	//sw.ParseParValJson(strTemp);
	//strBuf=sw.GenYqhInsertSQL();
	//strBuf = sw.GenSetRedisString();
	//gl.tlm.m_aWells.SetAt(0, sw);
}


void CMainFrame::OnSysStart()
{
	std::string address = "192.168.147.1";
	WriteLog(address);
	/* 测试拼音转换
	CString strTemp=gl.m_cH2P.GetLetter(_T("吐格6井"));
	AfxMessageBox(strTemp);
	return;
	if (!gl.OpenMasterDb())
	{
		gl.m_strNewMsg = _T("启动失败...连接中心库失败！");
		return;
	}
	gl.CreateLtdTable(_T("恰探1"), 2,,TRUE);
	return;*/
	/*	//功能测试使用
	SINGLE_WELL sw;
	sw.strWN = _T("Test");
	sw.strWellID = _T("Test01");
	sw.strWBID = _T("Test001");
	gl.tlm.m_aWells.Add(sw);
	for(int i=0;i<1000;i++)
		Test();
	return;*/
	// TODO: 在此添加命令处理程序代码
	g_bExitApp = FALSE;
	WriteLog(_T("准备启动数据同步..."));
	gl.m_strNewMsg = _T("准备启动数据同步...");
	for (int i = 0; i < MAXWELLS; i++)
	{
		if (pThread[i] != NULL)
		{
			pThread[i]->ExitInstance();
			pThread[i] = NULL;
		}
	}
	//gl.ReadSoftCfg();
	//gl.LoadWellsCfg();
	if (gl.m_nToRedis == 1)
	{
		Redis_DisConnect();
		if (Redis_Connect() == 1)
			gl.m_bConnectRedis = TRUE;
		else
		{
			AfxMessageBox(_T("连接REDIS数据库失败！"), MB_ICONINFORMATION);
			gl.m_strNewMsg = _T("启动失败...连接REDIS数据库失败！");
			return;
		}
	}
	if (gl.m_nToMaster == 1)
	{
		if (!gl.OpenMasterDb(TRUE))
		{
			gl.m_strNewMsg = _T("启动失败...连接中心库失败！");
			return;
		}
	}
	if (gl.m_nToYqh == 1)
	{
		if (!gl.OpenYqhDb(TRUE))
		{
			gl.m_strNewMsg = _T("启动失败...连接一体化库失败！");
			return;
		}
	}
	if (gl.m_nToKd == 1)
	{
		if (!gl.OpenKdDb(TRUE))
		{
			gl.m_strNewMsg = _T("启动失败...连接KD库失败！");
			return;
		}
	}

	QueryWellPars();
	m_nWells = gl.tlm.m_aWells.GetCount();
	if (m_nWells > MAXWELLS) m_nWells = MAXWELLS;
	for (int i = 0; i < m_nWells; i++)
		CreateOneThread(i);

	AfxBeginThread(YqhUrlThread1, NULL, THREAD_PRIORITY_NORMAL);//上传接口,这是后续
	//AfxBeginThread(YqhUrlThread2, NULL, THREAD_PRIORITY_NORMAL);//上传接口,这是后续
	AfxBeginThread(YqhDbThread1, NULL, THREAD_PRIORITY_NORMAL);
	AfxBeginThread(YqhDbThread2, NULL, THREAD_PRIORITY_NORMAL);
	AfxBeginThread(YqhDbThread3, NULL, THREAD_PRIORITY_NORMAL);
	AfxBeginThread(YqhDbThread4, NULL, THREAD_PRIORITY_NORMAL);
	AfxBeginThread(ZxkDbThread1, NULL, THREAD_PRIORITY_NORMAL);
	AfxBeginThread(ZxkDbThread2, NULL, THREAD_PRIORITY_NORMAL);
	AfxBeginThread(ZxkDbThread3, NULL, THREAD_PRIORITY_NORMAL);
	AfxBeginThread(ZxkDbThread4, NULL, THREAD_PRIORITY_NORMAL);
	AfxBeginThread(KdDbThread1, NULL, THREAD_PRIORITY_NORMAL);
	AfxBeginThread(KdDbThread2, NULL, THREAD_PRIORITY_NORMAL);
	AfxBeginThread(RedisThread, NULL, THREAD_PRIORITY_NORMAL);

	WriteLog(_T("启动数据同步..."));
	gl.m_strNewMsg = _T("进行井数据查询...");
	gl.m_bRunSync = TRUE;
}

void	CMainFrame::CreateOneThread(int nIndex)
{
	pThread[nIndex] = new CTlmWebserviceThread();
	if (pThread[nIndex] == nullptr) return;
	ASSERT_VALID(pThread[nIndex]);
	pThread[nIndex]->m_pThreadParams = nullptr;
	if (!pThread[nIndex]->CreateThread(CREATE_SUSPENDED))
	{
		delete pThread[nIndex];
		pThread[nIndex] = nullptr;
		return;
	}
	VERIFY(pThread[nIndex]->SetThreadPriority(THREAD_PRIORITY_NORMAL));
	pThread[nIndex]->m_nWellIndex = nIndex;
	pThread[nIndex]->ResumeThread();
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//数据湖接口实现
CString GetWellPars(CString strBoreID, CString strBearerCode)
{
	CString strTemp, strReturn = _T("");
	CString URLGET, AUTH;

	try
	{
		// 格式化URL和Authorization头
		URLGET.Format(_T("%s?tenant=TL.ZSX&UID_TAG=%s&version=oldVersion"), gl.tlm.strURL1, strBoreID);
		AUTH.Format(_T("Authorization: Bearer %s"), strBearerCode);

		// 记录日志（如果需要调试日志，可以解除注释）
		// WriteLog(_T("URLGET: ") + URLGET);
		// WriteLog(_T("AUTH: ") + AUTH);

		// 将CString转为char*（注意内存管理）
		char* auth = wchar2char(AUTH);
		char* urlget = wchar2char(URLGET);

		// 创建新的SOAP对象
		struct soap* soap = soap_new();

		// 设置http头部信息
		soap->http_extra_header = auth;

		// 注册插件
		soap_register_plugin(soap, http_get);

		// 尝试建立HTTP连接
		if (soap_http_get_connect(soap, urlget, NULL) || soap_begin_recv(soap))
		{
			// 连接或接收失败时打印错误并记录日志
			soap_print_fault(soap, stderr);
			WriteLog(_T("Error: GetWellPars->soap_http_get_connect\t") + strBoreID);

			// 释放资源并返回空字符串
			soap_destroy(soap);
			soap_end(soap);
			soap_done(soap);
			soap_free(soap);
			delete[] auth;
			delete[] urlget;
			return _T("");
		}

		// 处理返回的HTTP内容（可选）
		if (soap->http_content)
		{
			// 这里可以根据需要处理HTTP内容
			// 例如，输出HTTP内容的类型
			// strTemp.Format(_T("HTTP Content Type: %s"), char2wchar(soap->http_content));
			// AfxMessageBox(strTemp);
		}

		// 获取HTTP响应的主体内容
		size_t len;
		char* body = NULL;
		soap_http_body(soap, &body, &len);
		soap_end_recv(soap);

		// 处理响应体并返回结果
		if (body)
		{
			strReturn.Format(_T("%s"), char2wchar(body));
		}

		// 释放SOAP对象
		soap_destroy(soap);
		soap_end(soap);
		soap_done(soap);
		soap_free(soap);

		// 释放分配的内存
		delete[] auth;
		delete[] urlget;
	}
	catch (const std::exception& e)
	{
		// 捕获标准异常并记录日志
		std::string tt = "Exception: ";
		tt += e.what();
		WriteLog(tt);
		return _T("");
	}
	catch (const _com_error& e)
	{
		// 捕获COM异常并记录日志
		std::string tt = "Exception: ";
		tt += e.Description();
		WriteLog(tt);
		return _T("");
	}
	catch (...)
	{
		// 捕获所有其他类型的异常
		WriteLog(_T("Unknown Exception occurred in GetWellPars"));
		return _T("");
	}

	return strReturn;
}

//查询井的参数
void CMainFrame::QueryWellPars()
{
	CString strTemp;
	::EnterCriticalSection(&m_cWS);
	int nWells = gl.tlm.m_aWells.GetCount();
	WriteLog(_T("进行井参数查询..."));
	gl.m_strNewMsg = _T("进行井参数查询...");
	//查询井参数
	for (int i = 0; i < nWells; i++)
	{
		SINGLE_WELL sw = gl.tlm.m_aWells.GetAt(i);
		WriteLog(_T("井参数查询：\t") +sw.strWN);
		sw.nNewDataTime = CTime::GetCurrentTime().GetTime();
		sw.nNewDataTime = long(sw.nNewDataTime / gl.m_nTimeSpan)*gl.m_nTimeSpan;		//取整
		CString strPars = GetWellPars(sw.strWBID, gl.m_strBearerCode);
		//WriteLog(_T("井参数查询结果：\t") + sw.strWN  + strPars);
		int nErrorIndex = strPars.Find(_T("服务异常"));
		if (strPars != _T("[ ]")&& nErrorIndex<0){
			sw.ParseParsNameJson(strPars);
		}
		else
		{
			sw.bErrorGetPars = TRUE;
			gl.m_strNewMsg = _T("井参数查询结果：\t") + sw.strWN + _T("\t 无参数返回！");
			WriteLog(_T("井参数查询结果：\t") + sw.strWN + _T("\t 无参数返回！"));
			if (nErrorIndex > 0)
			{
				AfxMessageBox(_T("新疆数据湖服务异常！"),MB_ICONINFORMATION);
				break;
			}
		}
		//将KD表名生成一下
		strTemp = sw.strWN;
		strTemp.Replace(_T("-"), _T("_"));
		sw.strKdWellTable = gl.m_cH2P.GetLetter(strTemp);
		//根据总开关更改一下状态
		if (gl.m_nToMaster == 0) sw.nToZxq = 0;
		if (gl.m_nToYqh == 0) sw.nToYqh = 0;
		if (gl.m_nToKd == 0) sw.nToKD = 0;
		//gl.tlm.m_aWells.SetAt(i, sw);

		::EnterCriticalSection(&m_cWS);
		gl.tlm.m_aWells.SetAt(i, sw);
		::LeaveCriticalSection(&m_cWS);
		Sleep(500);
	}
	//查询一下井深在对照表中的位置
	gl.DepthIndex = gl.pi.FindCurDepthIndex();
	::LeaveCriticalSection(&m_cWS);
}

void CMainFrame::OnSysStop()
{
	// TODO: 在此添加命令处理程序代码
	g_bExitApp = TRUE;
	gl.m_bRunSync = FALSE;
	Sleep(10000);
	for (int i = 0; i < MAXWELLS; i++)
	{
		if (pThread[i] != NULL)
		{
			pThread[i]->ExitInstance();
		}
	}
	if (m_pConSys != NULL)
	{
		m_pConSys->Close();
		m_pConSys = NULL;
	}
	if (m_pConMaster != NULL)
	{
		m_pConMaster->Close();
		m_pConMaster = NULL;
	}
	if (m_pConKD != NULL)
	{
		m_pConKD->Close();
		m_pConKD = NULL;
	}
	if (gl.m_nToRedis == 1)
		Redis_DisConnect();
	gl.m_strNewMsg = _T("停止数据同步...");
	WriteLog(_T("停止数据同步..."));
}

void CMainFrame::OnUpdateSysStart(CCmdUI *pCmdUI)
{
	// TODO: 在此添加命令更新用户界面处理程序代码
	pCmdUI->Enable(!gl.m_bRunSync);
}

void CMainFrame::OnUpdateSysStop(CCmdUI *pCmdUI)
{
	// TODO: 在此添加命令更新用户界面处理程序代码
	pCmdUI->Enable(gl.m_bRunSync);
}

void CMainFrame::OnAppExit()
{
	if (AfxMessageBox(_T("请确认退出 德玛新疆实时数据采集软件？"), MB_YESNO | MB_ICONINFORMATION) == IDYES)
	{
		if (m_nTimer != 0)
			KillTimer(m_nTimer);
		if (gl.m_bRunSync)
		{
			g_bExitApp = TRUE;
			Sleep(10000);
			gl.m_bRunSync = FALSE;
		}
		for (int i = 0; i < MAXWELLS; i++)
		{
			if (pThread[i] != NULL)
			{
				pThread[i]->ExitInstance();
			}
		}
		if (m_pConSys != NULL)
		{
			m_pConSys->Close();
			m_pConSys = NULL;
		}
		if (m_pConMaster != NULL)
		{
			m_pConMaster->Close();
			m_pConMaster = NULL;
		}
		if (m_pConKD != NULL)
		{
			m_pConKD->Close();
			m_pConKD = NULL;
		}
		if (gl.m_nToRedis == 1)
			Redis_DisConnect();
		gl.SaveWellsCfg();

		CFrameWndEx::OnClose();
	}
}

void CMainFrame::OnTimer(UINT_PTR nIDEvent)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	if (nIDEvent == m_nTimer && m_strOldMsg != gl.m_strNewMsg)
	{
		m_strOldMsg = gl.m_strNewMsg;
		m_wndStatusBar.SetPaneText(1, gl.m_strNewMsg);
	}

	if (nIDEvent == m_nTimer && m_bFirst)
	{
		m_bFirst = FALSE;
		OnSysStart();
	}
	if (nIDEvent == m_nTimer) {
		for (int i = 0; i < m_nWells; ++i) {
			SINGLE_WELL sw = gl.tlm.m_aWells.GetAt(i);
			if (sw.m_stop==true)
			{
				CString strTemp;
				strTemp.Format(_T("OnTimer 重新 启动线程：index:%d, 井名:%s, 井筒id:%s"),i, sw.strWN, sw.strWBID);
				WriteLog(strTemp);
				delete pThread[i];
				pThread[i] = nullptr;
				CreateOneThread(i);
			}

		}
	}
	CFrameWndEx::OnTimer(nIDEvent);
}


void CMainFrame::OnClose()
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	return;
	CFrameWndEx::OnClose();
}

